package com.chat.controller;

import com.chat.service.FriendService;
import com.chat.util.Result;
import com.chat.util.SecurityHolderUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 好友控制器
 *
 * @author wb
 * @since 2025-06-07
 */

@RestController
@RequestMapping("/friend")
public class FriendController {

    @Autowired
    private FriendService friendService;


    @RequestMapping("/add")
    public Result<?> addFriend(@RequestParam("friendInfo") String friendInfo, @RequestParam("verifyMsg") String verifyMsg, HttpSession session) {
        return friendService.addFriend(SecurityHolderUtil.getUserId(session), friendInfo, verifyMsg) ? Result.ok() : Result.fail();
    }

    @RequestMapping("/respond")
    public Result<?> respondFriend(@RequestParam("requestId") Integer id, @RequestParam("status") Integer status) {
        return friendService.respondFriend(id, status) ? Result.ok() : Result.fail();
    }

    @RequestMapping("/requests")
    public Result<?> deleteFriend(HttpSession session) {
        return Result.ok(friendService.getFriendRequests(SecurityHolderUtil.getUserId(session)));
    }


    @GetMapping("/delete/{id}")
    public Result<?> deleteFriend(@PathVariable("id") Integer id, HttpSession session) {
        return friendService.deleteFriend(SecurityHolderUtil.getUserId(session), id) ? Result.ok() : Result.fail();
    }
}
